package com.hf.buildtb.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.DailyRollingFileAppender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hf.base.shh.BaseServiceImpl;
import com.hf.buildtb.dao.BiCorporationDao;
import com.hf.buildtb.dao.BiDepartmentClassDao;
import com.hf.buildtb.dao.BiDepartmentDao;
import com.hf.buildtb.entity.BiCooperator;
import com.hf.buildtb.entity.BiCorporation;
import com.hf.buildtb.entity.BiDepartment;
import com.hf.buildtb.entity.BiDepartmentClass;
import com.hf.buildtb.formodel.BiDepartmentForm;
import com.hf.buildtb.service.BiDepartmentService;

@Service("biDepartmentService")
public class BiDepartmentServiceImpl extends BaseServiceImpl<BiDepartmentForm, BiDepartment, BiDepartmentDao> implements BiDepartmentService {

	@Autowired
	BiCorporationDao biCorporationDao;
	@Autowired
	BiDepartmentClassDao biDepartmentClassdao;
	
	 @Override
	public BiDepartmentForm getPage(BiDepartment entity) {
		// TODO Auto-generated method stub
		 BiDepartmentForm  bForm =super.getPage(entity);
		 String hql = " from  BiCorporation where isValid=:isValid" ;
		 Map<String, Object> parameters = new HashMap<String, Object>();
		 parameters.put("isValid", true);
		 List<BiCorporation> coprlist=	biCorporationDao.find(hql,parameters);
		 
		 bForm.setCorpList(coprlist);
		 
		  hql = " from  BiDepartmentClass where isValid=:isValid" ;
		 List<BiDepartmentClass> classlist=	biDepartmentClassdao.find(hql,parameters);
		 		 
		 bForm.setClassList(classlist);	 
		return bForm;
	}
	 @Override
	public boolean saveEntity(BiDepartment entiy) {
		// TODO Auto-generated method stub
		 BiDepartmentClass bClass = biDepartmentClassdao.get(entiy.getDepClass(),entiy.getDepClass().getClassId());
		 entiy.setDepClass(bClass);
		 
		 BiCorporation biCorporation =biCorporationDao.get(entiy.getCorporation(),entiy.getCorporation().getCorpId());
		 entiy.setCorporation(biCorporation);
		  dao.merge(entiy); 
		  return true;
		 //return super.saveEntity(entiy);
	}
	
}
